home *** CD-ROM | disk | FTP | other *** search
- WiseStampFeedWrapper.prototype = new Object;
- WiseStampFeedWrapper.prototype.format = WiseStampFeedWrapper_format;
- WiseStampFeedWrapper.prototype.formatNoHtml = WiseStampFeedWrapper_formatNoHtml;
- WiseStampFeedWrapper.prototype.getLatestPost = WiseStampFeedWrapper_getLatestPost;
- WiseStampFeedWrapper.prototype.refreshCache = WiseStampFeedWrapper_refreshCache;
- WiseStampFeedWrapper.prototype.setLatestPostInCache = WiseStampFeedWrapper_setLatestPostInCache;
-
- function WiseStampFeedWrapper(feed, formatter)
- {
- this._feed = feed;
- this._formatter = formatter;
- this._latestPostCached = null;
- this._latestPostCachedDate = null;
- this.CACHE_TIMEOUT = 5 * 60 * 1000; // sasha
- }
-
- function WiseStampFeedWrapper_format()
- {
- if (!this._latestPostCached)
- {
- return '';
- };
- return this._formatter.format(this._latestPostCached);
- }
-
- function WiseStampFeedWrapper_formatNoHtml()
- {
- if (!this._latestPostCached)
- {
- return '';
- };
-
- return this._formatter.formatNoHtml(this._latestPostCached);
- }
-
- function WiseStampFeedWrapper_getLatestPost()
- {
- return this._latestPostCached;
- }
-
- function WiseStampFeedWrapper_refreshCache(callback)
- {
- WiseStampUtils.log("[feed.wrapper.js::WiseStampFeedWrapper_refreshCache] >>>>>");
- var _this = this;
-
- var expired = false;
-
- if (this._latestPostCachedDate)
- {
- var current = new Date();
- var expires = new Date().setTime(this._latestPostCachedDate.getTime() + this.CACHE_TIMEOUT);
- //dump("CURRENT: "); dump(current.toString());
- //dump("EXPIRES: "); dump(expires.toString());
- //dump("\n");
- expired = expires < current;
- //WiseStampUtils.log("[feed.wrapper.js::WiseStampFeedWrapper_refreshCache] current="+current+", expires="+expires.toString()+", expired="+expired);
- };
-
- if (this._latestPostCached && !expired)
- {
- WiseStampUtils.log("[feed.wrapper.js::WiseStampFeedWrapper_refreshCache] return cached");
-
- //dump("NOT EXPIRED\n");
- callback();
- return;
- };
-
- WiseStampUtils.log("[feed.wrapper.js::WiseStampFeedWrapper_refreshCache] fetching new...");
-
- this._feed.fetch(function (content)
- {
- var filter = new WiseStampRSSDataFilter();
- var latestPost = filter.getLatestPost(content);
-
- if (!latestPost)
- {
- callback();
- return;
- };
-
- _this.setLatestPostInCache(latestPost);
- callback();
- return;
- });
- // window.setTimeout(function() { throw new Error("[debug] " + "6c - "); }, 0);
- }
-
- function WiseStampFeedWrapper_setLatestPostInCache(post)
- {
- this._latestPostCachedDate = new Date();
- this._latestPostCached = post;
- }